<?php

namespace app\admin\controller\diy;

use app\admin\controller\AdminController;
use app\admin\service\diy\DiyService;
use app\admin\validate\diy\DiyValidate;
use think\response\Json;

class Diy extends AdminController
{
    /**
     * 获取首页数据
     * @return Json
     */
    public function getHomePageData()
    {
        $params = (new DiyValidate())->checkParam('get');
        $params['name'] = 'home_page';
        $result = DiyService::detail($params);
        return $this->data($result);
    }

    /**
     * 设置首页数据
     * @return Json
     */
    public function setHomePageData()
    {
        $params = (new DiyValidate())->checkParam('set');
        $params['name'] = 'home_page';
        $result = DiyService::edit($params);
        if (true === $result) {
            return $this->success([],'设置成功');
        } else {
            return $this->error(DiyService::getError());
        }
    }

    /**
     * 获取个人中心数据
     * @return Json
     */
    public function getPersonCenterData()
    {
        $params = (new DiyValidate())->checkParam('get');
        $params['name'] = 'person_center';
        $result = DiyService::detail($params);
        return $this->data($result);
    }

    /**
     * 设置个人中心数据
     * @return Json
     */
    public function setPersonCenterData()
    {
        $params = (new DiyValidate())->checkParam('set');
        $params['name'] = 'person_center';
        $result = DiyService::edit($params);
        if (true === $result) {
            return $this->success([],'设置成功');
        } else {
            return $this->error(DiyService::getError());
        }
    }

    /**
     * 获取客服页面数据
     * @return Json
     */
    public function getServicePageData()
    {
        $params = (new DiyValidate())->checkParam('get');
        $params['name'] = 'service_page';
        $result = DiyService::detail($params);
        return $this->data($result);
    }

    /**
     * 设置客服页面数据
     * @return Json
     */
    public function setServicePageData()
    {
        $params = (new DiyValidate())->checkParam('set');
        $params['name'] = 'service_page';
        $result = DiyService::edit($params);
        if (true === $result) {
            return $this->success([],'设置成功');
        } else {
            return $this->error(DiyService::getError());
        }
    }


    /**
     * 获取样式数据
     * @return Json
     */
    public function getStyleData()
    {
        $params = (new DiyValidate())->checkParam('get');
        $params['name'] = 'style';
        $result = DiyService::detail($params);
        return $this->data($result);
    }

    /**
     * 设置样式数据
     * @return Json
     */
    public function setStyleData()
    {
        $params = (new DiyValidate())->checkParam('set');
        $params['name'] = 'style';
        $result = DiyService::edit($params);
        if (true === $result) {
            return $this->success([],'设置成功');
        } else {
            return $this->error(DiyService::getError());
        }
    }

    /**
     * 获取底部导航数据
     * @return Json
     */
    public function getTabbarData()
    {
        $params = (new DiyValidate())->checkParam('get');
        $params['name'] = 'tabbar';
        $result = DiyService::detail($params);
        return $this->data($result);
    }

    /**
     * 设置底部导航数据
     * @return Json
     */
    public function setTabbarData()
    {
        $params = (new DiyValidate())->checkParam('set');
        $params['name'] = 'tabbar';
        $result = DiyService::edit($params);
        if (true === $result) {
            return $this->success([],'设置成功');
        } else {
            return $this->error(DiyService::getError());
        }
    }

}